package com.example.smartcity.ui.Adapter;

import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.smartcity.R;
import com.example.smartcity.ui.Bean.loginList;

import java.util.ArrayList;
import java.util.List;

public class loginAdapter extends ArrayAdapter {

    private int resource;
    private ArrayList<loginList> loginLists;

    public loginAdapter(@NonNull Context context, int resource,ArrayList<loginList> list) {
        super(context, resource,list);
        this.resource = resource;
        this.loginLists = list;
    }


    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        loginList list = (loginList) getItem(position);
        View view;
        ViewHolder viewHolder = null;
        if (convertView==null){
            view = LayoutInflater.from(getContext()).inflate(resource,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.imageView = view.findViewById(R.id.IV_icon);
            viewHolder.editText = view.findViewById(R.id.ET_Message);
            viewHolder.editText.setTag(position);
            view.setTag(viewHolder);
        }else{
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.imageView.setImageResource(list.getIcon());
        viewHolder.editText.setHint(list.getHint());
        return view;
    }

    class ViewHolder{
        ImageView imageView;
        EditText editText;
    }
}
